package com.example.qincetest.ui.disney

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.qincetest.R

@Composable
fun DisneyHomeScreen() {
    Column(
        modifier = Modifier
            .fillMaxSize()
            .background(Color.White)
    ) {
        // Banner Section
        Box(
            modifier = Modifier
                .fillMaxWidth()
                .height(300.dp)
                .background(
                    color = Color(0xFF1E3C72)
                )
        ) {
            Column(
                modifier = Modifier
                    .fillMaxSize()
                    .padding(24.dp),
                verticalArrangement = Arrangement.Bottom
            ) {
                Text(
                    text = "祝你",
                    color = Color.White,
                    fontSize = 24.sp,
                    fontWeight = FontWeight.Bold
                )
                Text(
                    text = "圣诞奇妙",
                    color = Color.White,
                    fontSize = 32.sp,
                    fontWeight = FontWeight.Bold
                )
            }
        }

        // Quick Actions Grid
        QuickActionsGrid()

        // Notice Section
        NoticeSection()

        // Park Hours Section
        ParkHoursSection()

        // Bottom Navigation
        BottomNavigation()
    }
}

@Composable
fun QuickActionsGrid() {
    Column(
        modifier = Modifier
            .fillMaxWidth()
            .padding(16.dp)
    ) {
        Row(
            modifier = Modifier.fillMaxWidth(),
            horizontalArrangement = Arrangement.SpaceBetween
        ) {
            QuickActionItem("门票", R.drawable.ic_ticket)
            QuickActionItem("酒店", R.drawable.ic_hotel)
            QuickActionItem("年卡", R.drawable.ic_annual_pass)
            QuickActionItem("尊享卡", R.drawable.ic_vip_card)
            QuickActionItem("乐园早享卡", R.drawable.ic_early_entry)
        }
        
        Spacer(modifier = Modifier.height(16.dp))
        
        Row(
            modifier = Modifier.fillMaxWidth(),
            horizontalArrangement = Arrangement.SpaceBetween
        ) {
            QuickActionItem("领券中心", R.drawable.ic_coupon)
            QuickActionItem("游园攻略", R.drawable.ic_guide)
            QuickActionItem("玩乐表演", R.drawable.ic_show)
            QuickActionItem("餐饮", R.drawable.ic_food)
            QuickActionItem("全部", R.drawable.ic_all)
        }
    }
}

@Composable
fun QuickActionItem(text: String, iconRes: Int) {
    Column(
        horizontalAlignment = Alignment.CenterHorizontally,
        modifier = Modifier.padding(4.dp)
    ) {
        Icon(
            painter = painterResource(id = iconRes),
            contentDescription = text,
            modifier = Modifier
                .size(40.dp)
                .clip(RoundedCornerShape(8.dp))
                .background(Color(0xFF4285F4)),
            tint = Color.White
        )
        Spacer(modifier = Modifier.height(4.dp))
        Text(
            text = text,
            fontSize = 12.sp
        )
    }
}

@Composable
fun NoticeSection() {
    Row(
        modifier = Modifier
            .fillMaxWidth()
            .padding(horizontal = 16.dp),
        verticalAlignment = Alignment.CenterVertically
    ) {
        Text(
            text = "消息通知",
            fontWeight = FontWeight.Bold
        )
        Text(
            text = "上海迪士尼度假区实名制购票政策...",
            modifier = Modifier
                .weight(1f)
                .padding(horizontal = 8.dp)
        )
        Text(
            text = "全部 >",
            color = Color.Gray
        )
    }
}

@Composable
fun ParkHoursSection() {
    Row(
        modifier = Modifier
            .fillMaxWidth()
            .padding(16.dp),
        verticalAlignment = Alignment.CenterVertically
    ) {
        Icon(
            painter = painterResource(id = R.drawable.ic_calendar),
            contentDescription = "Calendar",
            modifier = Modifier.size(24.dp)
        )
        Column(
            modifier = Modifier
                .weight(1f)
                .padding(horizontal = 8.dp)
        ) {
            Text(
                text = "乐园运营时间·12月1日",
                fontWeight = FontWeight.Bold
            )
            Text(
                text = "08:30 至 20:30",
                fontSize = 20.sp,
                fontWeight = FontWeight.Bold
            )
        }
        Text(
            text = "更多日期 >",
            color = Color.Gray
        )
    }
}

@Composable
fun BottomNavigation() {
    Row(
        modifier = Modifier
            .fillMaxWidth()
            .background(Color.White)
            .padding(8.dp),
        horizontalArrangement = Arrangement.SpaceAround
    ) {
        BottomNavItem("首页", R.drawable.ic_home, true)
        BottomNavItem("商城", R.drawable.ic_shop)
        BottomNavItem("地图", R.drawable.ic_map)
        BottomNavItem("行程", R.drawable.ic_schedule)
        BottomNavItem("我的", R.drawable.ic_profile)
    }
}

@Composable
fun BottomNavItem(text: String, iconRes: Int, selected: Boolean = false) {
    Column(
        horizontalAlignment = Alignment.CenterHorizontally,
        modifier = Modifier.padding(4.dp)
    ) {
        Icon(
            painter = painterResource(id = iconRes),
            contentDescription = text,
            tint = if (selected) Color(0xFF4285F4) else Color.Gray,
            modifier = Modifier.size(24.dp)
        )
        Text(
            text = text,
            color = if (selected) Color(0xFF4285F4) else Color.Gray,
            fontSize = 12.sp
        )
    }
}

@Preview(showBackground = true, backgroundColor = 0xFFFFFFFF)
@Composable
fun DisneyHomeScreenPreview() {
    DisneyHomeScreen()
}
